/**
*   description:
*       ring_buffer, mainly used for storage media stream. 
*
*   author:     yangdong
*   date:       20200329
*   home_page:  https://blog.csdn.net/heibao111728
*/
#ifndef __D_RING_BUFFER_H__
#define __D_RING_BUFFER_H__

#include <iostream>
#include <mutex>

namespace dutils 
{
    class dring_buffer
    {
    public:
        dring_buffer(int capacity = 2 * 1024 * 1024);
        ~dring_buffer();

        int capacity();
        int size();

        int left_space();

        int push(unsigned char* data, int data_size);
        int pop(unsigned char* data, int data_size);

        void clean();

    private:
        unsigned char* m_buffer;

        int m_capacity;
        int m_size;

        int m_head;
        int m_tail;

        std::mutex m_lock;
    };
}



#endif
